﻿// Function for the inviteUserDialog JqueryUI dialog used for inviting users to a game.
$("#inviteUserDialog").dialog({
    autoOpen: false,
    height: 250,
    width: 300,
    modal: true,
    buttons: {
        "Bjóða": function () {
            var user = $("#inviteUserDialog #user").val();
            if (user.length > 0 && user.length < 26) {
                var myHub = $.connection.masterHub;
                myHub.server.inviteUser(group, gameRoomModel.currentUserName, user);
                $(this).dialog("close");
            }
            else
                alert("Nafn má bara vera 1-25 að lengd!");
        },
        Cancel: function () {
            $(this).dialog("close");
        }
    },
    open: function () {
        $("#inviteUserDialog #user").css("width", "95%");
    },
    close: function () {
    }
});

// Function for the inviteUserIdDialog JqueryUI dialog used for inviting users by id to a game.
$("#inviteUserIdDialog").dialog({
    autoOpen: false,
    height: 250,
    width: 300,
    modal: true,
    buttons: {
        "Bjóða": function () {
            var userId = $("#inviteUserIdDialog #userId").val()
            if ($.isNumeric(userId) && userId.length > 0) {
                var myHub = $.connection.masterHub;
                myHub.server.inviteId(group, gameRoomModel.currentUserName, userId);
                $(this).dialog("close");
            }
            else
                alert("ID á leikmanni má bara innihalda tölur!!");
        },
        Cancel: function () {
            $(this).dialog("close");
        }
    },
    open: function () {
        $("#inviteUserIdDialog #userId").css("width", "95%");
    },
    close: function () {
    }
});

// Opens the dialog.
inviteByUser = function () {
    $("#inviteUserDialog").dialog("open");
}

// Opens the dialog.
inviteByUserId = function () {
    $("#inviteUserIdDialog").dialog("open");
}

$("#invitationRecieved").dialog({
    autoOpen: false,
    height: 250,
    width: 375,
    modal: true,
    buttons: {
        "Taka þátt": function () {
            window.open('/GameRoom/Join/' + gameRoomInvite);
            $(this).dialog("close");
        },
        Cancel: function () {
            $(this).dialog("close");
        }
    }
});